package org.myself.meeting.controller;

import org.myself.meeting.Utils.Constant;
import org.myself.meeting.model.Base;
import org.myself.meeting.model.Employee;
import org.myself.meeting.model.NotifyBase;
import org.myself.meeting.model.Result;
import org.myself.meeting.service.MyMeetingService;
import org.myself.meeting.service.NewMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
public class NewMessageController {

    @Autowired
    NewMessageService newMessageService;

    //最新通知
    @RequestMapping("/personal/notify")
    @ResponseBody
    public Result newMessage(@RequestBody NotifyBase base){
        long total = newMessageService.getCountAll();
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("news",newMessageService.getNewMessage(base.getPages(), Constant.PAGESIZE));
        map.put("total",total);
        map.put("page",base.getPages());
        map.put("pagenum",total%Constant.PAGESIZE==0?total/Constant.PAGESIZE : total/Constant.PAGESIZE+1 );
        return new Result(200,"success",map);
    }
}
